
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

public class SAXTest {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// 获取Sax解析工程对象
		SAXParserFactory factory = SAXParserFactory.newInstance();
		try {
			SAXParser parser = factory.newSAXParser();
			// 新建xml处理器
			SAXParserHandler handler = new SAXParserHandler();
			parser.parse("C:\\Users\\Administrator\\Desktop\\xmlchat\\xml-chat\\src\\test\\resources\\3.xml", handler);
			System.out.println("共有" + handler.getBookList().size() + "本书");
			for (Book book : handler.getBookList()) {
				System.out.println(book.getId());
				System.out.println(book.getBookname());
				System.out.println(book.getAuthor());
				System.out.println(book.getPrice());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
